
package com.yzkj.cpjxc.business.framework.utils.property;

import java.util.HashMap;
import java.util.Map;

/**
 * Property文件工厂（用单例来缓存Property文件）
 */
public class PropertyFactory {

	/**
	 * 懒汉模式的单例
	 */
	private static PropertyFactory factory = null;

	private PropertyFactory() {

	}

	/**
	 * 线程安全的创建实例
	 */
	public static PropertyFactory getInstance() {

		if (null == factory) {
			synchronized (PropertyFactory.class) {
				if (null == factory) {
					factory = new PropertyFactory();
				}
			}
		}

		return factory;
	}

	//定义 PropertyFileUtil 读取Property实例的Map。缓存 PropertyFileUtil 对象
	private static Map<String, PropertyFileUtil> propertyMap = new HashMap<String, PropertyFileUtil>();

	/**
	 * 根据文件和KEY，获取相应的值
	 */
	public String getPropertyByKey(String propertyFile, String propertyKey) {

		PropertyFileUtil property = propertyMap.get(propertyFile);

		if (property == null) {
			property = new PropertyFileUtil(propertyFile);
			propertyMap.put(propertyFile, property);
		}

		return property.getProperties(propertyKey);

	}

}
